package com.taiyuan.tongcheng.ui;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import net.sourceforge.simcpux.Constants;
import net.sourceforge.simcpux.MD5;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.kymjs.kjframe.KJHttp;
import org.kymjs.kjframe.http.HttpCallBack;
import org.kymjs.kjframe.http.HttpConfig;
import org.kymjs.kjframe.http.HttpParams;
import org.kymjs.kjframe.ui.BindView;
import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.DensityUtils;
import org.kymjs.kjframe.utils.KJLoger;
import org.kymjs.kjframe.utils.StringUtils;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.baidu.location.LLSInterface;
import com.taiyuan.tongcheng.adapter.CarKindAdapter;
import com.taiyuan.tongcheng.adapter.OderStationAdapter;
import com.taiyuan.tongcheng.adapter.OrderCancelAdapter;
import com.taiyuan.tongcheng.application.TCBroadcastAction;
import com.taiyuan.tongcheng.bean.ServerStation;
import com.taiyuan.tongcheng.bean.ZcExtraServiceInfo;
import com.taiyuan.tongcheng.bean.ZcOrderInfo;
import com.taiyuan.tongcheng.config.TcConfig;
import com.taiyuan.tongcheng.http.HttpParamUtil;
import com.taiyuan.tongcheng.http.TcWebservice;
import com.taiyuan.tongcheng.http.WebData;
import com.taiyuan.tongcheng.jsonparser.TcJsParser;
import com.taiyuan.tongcheng.pay.WxPay;
import com.taiyuan.tongcheng.ui.fragment.OrderCargoFragment;
import com.tencent.mm.sdk.modelpay.PayReq;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.tytc56.user.R;

public class OrderDetailActivity extends BaseActivity {

	// widget basic信息
	@BindView(id = R.id.tv_order_time)
	private TextView orderTimeTv;
	@BindView(id = R.id.tv_order_car)
	private TextView carStyleTv;
	@BindView(id = R.id.tv_order_service)
	private TextView serviceTv;
	@BindView(id = R.id.tv_order_state)
	private TextView orderStateTv;
	@BindView(id = R.id.tv_order_addinfo)
	private TextView addNoteTv;
	// list起点途径点信息
	@BindView(id = R.id.lv_sta_order)
	private ListView stationLv;

	// price价格
	@BindView(id = R.id.tv_all_price)
	private TextView allPriceTv;
	@BindView(id = R.id.tv_price_start)
	private TextView startPriceTv;
	@BindView(id = R.id.tv_price_km)
	private TextView kmPriceTv;
	@BindView(id = R.id.tv_price_service)
	private TextView servicePriceTv;
	@BindView(id=R.id.tv_price_lable)
	private TextView priceLable;
	@BindView(id=R.id.tv_price_coupon)
	private TextView couponPrice;
	@BindView(id=R.id.tv_price_night_cargo)
	private TextView  ninghtPrice;
	@BindView(id=R.id.tv_price_km_lable)
	private TextView  lichengPriceLable;
	@BindView(id=R.id.tv_price_start_lable)
	private TextView  startPriceLable;
	@BindView(id=R.id.tv_price_tujind)
	private TextView  tujindianPriceTv;
	@BindView(id=R.id.rl_price_discount)
	private RelativeLayout discountLayout;
	@BindView(id=R.id.tv_price_discount)
	private TextView  discountTv;
	// 工具bar
	@BindView(id = R.id.tv_order_price)
	private TextView orderPrice;
	@BindView(id = R.id.btn_order_kind, click = true)
	private Button orderPayBtn;
	@BindView(id = R.id.btn_order_mark, click = true)
	private Button orderMarkBtn;
	@BindView(id = R.id.btn_order_cancel, click = true)
	private Button orderCancelBtn;
	@BindView(id = R.id.btn_order_cakan, click = true)
	private Button orderCakanBtn;
	@BindView(id = R.id.btn_order_modify_confirm, click = true)
	private Button orderConfirmBtn;
	@BindView(id = R.id.rl_bottom)
	private RelativeLayout bottomRl;

	//配送司机信息
	@BindView(id=R.id.ll_order_driver_msg)
	private LinearLayout  driverLayout ;
	@BindView(id=R.id.tv_order_driver_name)
	private TextView  driverName;
	@BindView(id=R.id.tv_order_car_no)
	private TextView  driverCarno;
	@BindView(id=R.id.btn_order_driver_call,click=true)
	private Button   driverTelBtn ;
	
	// 评价
	@BindView(id = R.id.ll_order_mark)
	private LinearLayout markLinearLayout;
	@BindView(id = R.id.rataingBar)
	private RatingBar rationgBar;
	@BindView(id=R.id.tv_mark_time)
	private TextView  markTime;

	// 数据
	private ZcOrderInfo info = new ZcOrderInfo();
	private OderStationAdapter adapter;
	private List<ServerStation> stationList = new ArrayList<ServerStation>();
	private ServerStation startSta = new ServerStation();
	private ServerStation endSta = new ServerStation();
	private List<String> middlejsonString = new ArrayList<String>();
	

	// 微信支付
	// 微信
	private PayReq req;
	public IWXAPI msgApi;
	// 跳转intent
	private Intent cancelIntent;
	private Intent markIntent;
	private Intent positionIntent;
	private IntentFilter intentFilter;

	@Override
	public void setRootView() {
		super.setRootView();
		setContentView(R.layout.activity_order_detail);
	}

	@Override
	public void initWidget() {
		super.initWidget();
		initView();
		//支付参数
		msgApi=WXAPIFactory.createWXAPI(getApplicationContext(), null);
		req = new PayReq();
		info = (ZcOrderInfo) getIntent().getSerializableExtra(
				OrderCargoFragment.TAG_CARGO_ORDER);
		initBaseInfo(info);
		topTv.setText("订单详情");
		rightTv.setVisibility(View.GONE);
		registReceiver();
	}

	/**
	 * 
	 * @Description: 刷写界面
	 * @param info
	 * @return void
	 * @throws
	 * @autour wzq
	 * @date 2015-9-21 下午5:20:50
	 * @update (date)
	 */
	private void initBaseInfo(ZcOrderInfo info) {
		
		//司机信息
		if(info.getStatus()==TcConfig.OrderStatus.CANCEL||info.getStatus()==TcConfig.OrderStatus.PRE_RESPONSE){
			driverLayout.setVisibility(View.GONE);
		}else{
			driverLayout.setVisibility(View.VISIBLE);
			driverName.setText(info.getDriverName());
			driverCarno.setText(info.getTruckNumber());
		}
		
		// 价格信息
		DecimalFormat df = new DecimalFormat("0.0");
		startPriceLable.setText(getString(R.string.lable_price_start)+"(含"+info.getStartKm()+"公里)");
		allPriceTv.setText("￥"+(info.getActualOrderMoney()-info.getMoneyCardValue())+"");
		startPriceTv.setText("￥"+info.getStartPrice());
		kmPriceTv.setText("￥"+info.getLiChengPrice() + "");
		couponPrice.setText("￥-"+info.getMoneyCardValue());
		ninghtPrice.setText("￥"+info.getNightServicePrice());
		servicePriceTv.setText("￥"+(info.getExtraServicePrice()
				+ info.getWaitUserPice()) + "");
		if(info.getTotalKmNum()>info.getStartKm()){
			lichengPriceLable.setText(getString(R.string.lable_price_km)+"("+df.format(info.getTotalKmNum()-info.getStartKm())+"X"+info.getUnitPrice()+"元/公里)");
		}else{
			lichengPriceLable.setText(getString(R.string.lable_price_km));
		}
		
		if(info.getMiddlePlacePrice()>0){
			tujindianPriceTv.setText("￥"+info.getMiddlePlacePrice());
		}else{
			tujindianPriceTv.setText("￥ 0");
		}
		
		if(info.getDiscountMoney()>0){
			discountLayout.setVisibility(View.VISIBLE);
			discountTv.setText("￥"+info.getDiscountMoney());
		}
		
		priceLable.setText("订单总价（元）");
		// 服务信息
		orderTimeTv.setText(info.getServiceDate());
		carStyleTv.setText(CarKindAdapter.carName[info.getTruckTypeId() - 1]);
		if (StringUtils.isEmpty(info.getExtraServiceInfo())) {
			serviceTv.setText("无");
		} else {
			List<ZcExtraServiceInfo> list = new ArrayList<ZcExtraServiceInfo>();
			list = JSON.parseArray(info.getExtraServiceInfo(),
					ZcExtraServiceInfo.class);
			serviceTv.setText(info.getExtraServiceInfo());
			StringBuilder builder = new StringBuilder();
			for (int i = 0; i < list.size(); i++) {
				builder.append(list.get(i).getName() + "("+list.get(i).getPrice()+")");
			}
			serviceTv.setText(builder.toString());
		}
		
		
		orderStateTv.setText(TcConfig.getStateName(info.getStatus()));
		if (StringUtils.isEmpty(info.getNote())) {
			addNoteTv.setText("无");
		} else {
			addNoteTv.setText(info.getNote());
		}

		// 起始途径点
		startSta.setPlace(info.getStartPlace());
		startSta.setId(R.drawable.move_icon_start_active);
		endSta.setPlace(info.getEndPlace());
		endSta.setId(R.drawable.move_icon_end_active);
		stationList.add(startSta);
		if (info.getMiddlePlaceInfo().length() > 4) {
			List<ServerStation> middleSta = new ArrayList<ServerStation>();
			middlejsonString = JSON.parseArray(info.getMiddlePlaceInfo(),
					String.class);
			for (String serverStation : middlejsonString) {
				middleSta.add((ServerStation) JSON.parseObject(serverStation,
						ServerStation.class));
			}
			if (middleSta.size() > 0) {
				stationList.addAll(middleSta);
			}
		}
		stationList.add(endSta);
		KJLoger.debug(stationList.toString() + "ss" + stationList.size());
		LinearLayout.LayoutParams haltLisfLp = (LayoutParams) stationLv
				.getLayoutParams();
		haltLisfLp.height = stationList.size()
				* (DensityUtils.dip2px(this, 40) + 1);
		stationLv.setLayoutParams(haltLisfLp);
		// 途径点信息
		adapter = new OderStationAdapter(this, stationList);
		stationLv.setAdapter(adapter);
		// 评价信息
		rationgBar.setIsIndicator(true);
		if (info.getIsCommentFlag() == 1) {
			markLinearLayout.setVisibility(View.VISIBLE);
			rationgBar.setRating(Float.parseFloat(info.getCommentScore()));
			markTime.setText("评价时间:"+info.getCommentTime());
		} else {
			markLinearLayout.setVisibility(View.GONE);
		}
		// 更新订单bar
		initOrderBarUi(info);
	}

	/**
	 * 
	 * @Description: 刷新订单bar
	 * @param orderInfo
	 * @return void
	 * @throws
	 * @autour wzq
	 * @date 2015-9-14 下午7:18:36
	 * @update (date)
	 */
	private void initOrderBarUi(ZcOrderInfo orderInfo) {
		orderPrice.setVisibility(View.GONE);
		switch (orderInfo.getStatus()) {
		case TcConfig.OrderStatus.PRE_RESPONSE:
			orderStateTv.setText(TcConfig.OrderStatusLable.PRE_RES);
			orderMarkBtn.setVisibility(View.GONE);
			orderCakanBtn.setVisibility(View.GONE);
			orderCancelBtn.setVisibility(View.VISIBLE);
			if (orderInfo.getIsPayFlag() == 1) {
				orderPayBtn.setVisibility(View.GONE);
			} else {
				orderPayBtn.setVisibility(View.VISIBLE);
				if(orderInfo.getPayTypeId()!=1){
					orderPayBtn.setBackgroundResource(R.drawable.btn_disabled);
					orderPayBtn.setClickable(false);
				}
			}
			break;
		case TcConfig.OrderStatus.PRE_TAKEGOODS:
			orderStateTv.setText(TcConfig.OrderStatusLable.PRE_CARRAY);
			orderMarkBtn.setVisibility(View.GONE);
			orderCakanBtn.setVisibility(View.GONE);
			orderCancelBtn.setVisibility(View.GONE);

			if (orderInfo.getIsPayFlag() == 1) {
				orderPayBtn.setVisibility(View.GONE);
			} else {
				orderPayBtn.setVisibility(View.VISIBLE);
				if(orderInfo.getPayTypeId()!=1){
					orderPayBtn.setBackgroundResource(R.drawable.btn_disabled);
					orderPayBtn.setClickable(false);
				}
			}
			break;
		case TcConfig.OrderStatus.PRE_CARRY:
			orderStateTv.setText(TcConfig.OrderStatusLable.PRE_CARRAY);
			orderMarkBtn.setVisibility(View.GONE);
			orderCakanBtn.setVisibility(View.GONE);
			if (orderInfo.getIsPayFlag() == 1) {
				orderPayBtn.setVisibility(View.GONE);
			} else {
				orderPayBtn.setVisibility(View.VISIBLE);
				if(orderInfo.getPayTypeId()!=1){
					orderPayBtn.setBackgroundResource(R.drawable.btn_disabled);
					orderPayBtn.setClickable(false);
				}
			}
			break;
		case TcConfig.OrderStatus.FINISH:
			orderStateTv.setText(TcConfig.OrderStatusLable.FINISH);
			orderMarkBtn.setVisibility(View.VISIBLE);
			orderCakanBtn.setVisibility(View.GONE);
			orderCancelBtn.setVisibility(View.GONE);
			orderPayBtn.setVisibility(View.GONE);
			
			if (info.getIsCommentFlag() == 1) {
				orderMarkBtn.setVisibility(View.GONE);
			} else {
				orderMarkBtn.setVisibility(View.VISIBLE);
			}
			
			break;
		case TcConfig.OrderStatus.DELIVERING:
			orderStateTv.setText(TcConfig.OrderStatusLable.CARRAY_ING);
			orderCakanBtn.setVisibility(View.VISIBLE);
			orderPayBtn.setVisibility(View.GONE);
			orderMarkBtn.setVisibility(View.GONE);
			orderCancelBtn.setVisibility(View.GONE);
			break;
		case TcConfig.OrderStatus.CANCEL:
			bottomRl.setVisibility(View.GONE);
			orderStateTv.setText("已取消");
			orderPayBtn.setVisibility(View.GONE);
			orderMarkBtn.setVisibility(View.GONE);
			orderCakanBtn.setVisibility(View.GONE);
			orderCancelBtn.setVisibility(View.GONE);
			if (info.getIsCommentFlag() == 0) {
				markLinearLayout.setVisibility(View.GONE);
			} else {
				markLinearLayout.setVisibility(View.VISIBLE);
			}
			break;
		default:
			break;
		}

		if (orderInfo.getIsUserConfirmFlag().equals("0")) {
			orderConfirmBtn.setVisibility(View.VISIBLE);
			orderPayBtn.setVisibility(View.GONE);
		} else {
			orderConfirmBtn.setVisibility(View.GONE);
		}
		
		
	}

	
	
	
	@Override
	public void initData() {
		super.initData();
		cancelIntent = new Intent(this, OrderCancelActivity.class);
		markIntent = new Intent(this, MarkActivity.class);
		positionIntent = new Intent(this, TruckerPositionActivity.class);
	}

	@Override
	public void widgetClick(View v) {
		super.widgetClick(v);
		switch (v.getId()) {
		case R.id.btn_order_kind:
			payMoney(info.getZcOrderId());
			break;
		case R.id.btn_order_cancel:
			cancelIntent.putExtra(TcConfig.IntentTag.Order_Id,
					info.getZcOrderId());
			cancelIntent.putExtra(OrderCancelActivity.TAG_CANCEL_KIND,
					OrderCancelAdapter.CANCEL_ADAPTER_CARGO);
			KJLoger.debug("订单ID" + info.getZcOrderId());
			KJLoger.debug("订单NO" + info.getZcOrderNo());
			KJLoger.debug("订单状态" + info.getStatus());
			startActivity(cancelIntent);
			break;
		case R.id.btn_order_mark:
			markIntent.putExtra(MarkActivity.TAG_MARK_ORDER_FROM,
					MarkActivity.ORDER_FROM_CARGO);
			markIntent.putExtra(MarkActivity.TAG_MARK_ORDER_ID,
					info.getZcOrderId());
			startActivity(markIntent);
			break;
		case R.id.btn_order_cakan:
			positionIntent.putExtra(TruckerPositionActivity.TAG_DRIVER_ID,
					info.getDriverId());
			startActivity(positionIntent);
			break;

		case R.id.btn_order_modify_confirm:
			sendBroadcast(new Intent(TCBroadcastAction.DIALOG_SHOW));
			confirmOrderModify(info.getZcOrderId());
			break;
		case R.id.btn_order_driver_call:
			Intent intent = new Intent(Intent.ACTION_DIAL,Uri.parse("tel:"+ info.getDriverMobile()));
			intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			startActivity(intent);
			break;

		default:
			break;
		}
	}

	/**
	 * 
	 * @Description: 掉起微信支付
	 * @param orderId
	 * @return void
	 * @throws
	 * @autour wzq
	 * @date 2015-9-14 下午7:10:25
	 * @update (date)
	 */
	private void payMoney(String orderId) {
		HttpConfig config = new HttpConfig();
		config.cacheTime = 0;
		KJHttp kjh = new KJHttp(config);
		HttpParams params = new HttpParams();
		params = HttpParamUtil.getCarGoPayParams(this, orderId, "");
		kjh.post(TcWebservice.WEBSERVER_IP
				+ TcWebservice.API.FREIGHT_ORDER_WXPAY, params,
				new HttpCallBack() {

					@Override
					public void onSuccess(String t) {
						super.onSuccess(t);
						String str;
						try {
							str = URLDecoder.decode(new String(t), "UTF-8");
							KJLoger.debug(str);
							WebData webData = TcJsParser.getWedataData(str);
							if (webData.getStatus() == 1) {
								WxPay payParam = JSON.parseObject(
										webData.getData(), WxPay.class);
								// // 获取到订单后 调起 支付
								// PayInfo orderInfo = new PayInfo();
								// orderInfo.setOrderNo(payParam.getPrepayid());
								// testPay(PayAgent.PayType.UPPAY, orderInfo);
								initWxPay(payParam);
							} else {

							}

						} catch (UnsupportedEncodingException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void onFailure(int errorNo, String strMsg) {
						super.onFailure(errorNo, strMsg);
					}

					@Override
					public void onFinish() {
						super.onFinish();
					}
				});
	}

	/**
	 * 
	 * @Description: 获取验证密钥
	 * @param params
	 * @return
	 * @return String
	 * @throws
	 * @autour wzq
	 * @date 2015-9-14 上午8:23:03
	 * @update (date)
	 */
	private String genAppSign(List<NameValuePair> params) {
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < params.size(); i++) {
			sb.append(params.get(i).getName());
			sb.append('=');
			sb.append(params.get(i).getValue());
			sb.append('&');
		}
		sb.append("key=");
		sb.append(Constants.API_KEY);
		String appSign = MD5.getMessageDigest(sb.toString().getBytes())
				.toUpperCase();
		Log.e("orion", appSign);
		return appSign;
	}

	private void initWxPay(WxPay payParam) {
		req.appId = Constants.APP_ID;
		req.partnerId = Constants.MCH_ID;
		req.prepayId = payParam.getPrepayid();
		req.packageValue = "Sign=WXPay";
		req.nonceStr = payParam.getRad();
		req.timeStamp = System.currentTimeMillis() / 1000 + "";

		List<NameValuePair> signParams = new LinkedList<NameValuePair>();
		signParams.add(new BasicNameValuePair("appid", req.appId));
		signParams.add(new BasicNameValuePair("noncestr", req.nonceStr));
		signParams.add(new BasicNameValuePair("package", req.packageValue));
		signParams.add(new BasicNameValuePair("partnerid", req.partnerId));
		signParams.add(new BasicNameValuePair("prepayid", req.prepayId));
		signParams.add(new BasicNameValuePair("timestamp", req.timeStamp));
		// req.sign = payParam.getSign();
		req.sign = genAppSign(signParams);
		msgApi.registerApp(Constants.APP_ID);
		msgApi.sendReq(req);
	}

	/**
	 * 
	 * @Description: 订单确定修改
	 * @param orderId
	 * @return void
	 * @autour wzq
	 * @date 2015-9-21 下午4:32:52
	 * @update (date)
	 */
	private void confirmOrderModify(String orderId) {

		HttpConfig config = new HttpConfig();
		config.cacheTime = 0;
		KJHttp kjHttp = new KJHttp(config);
		HttpParams params = new HttpParams();
		params = HttpParamUtil.getConfirmModify(getApplicationContext(),
				orderId);
		kjHttp.post(TcWebservice.WEBSERVER_IP
				+ TcWebservice.API.FREIGHT_ORDER_UPDATE, params,
				new HttpCallBack() {
					@Override
					public void onFailure(int errorNo, String strMsg) {
						super.onFailure(errorNo, strMsg);
					}

					@Override
					public void onSuccess(String t) {
						try {
							String date = URLDecoder.decode(t, "UTF-8");
							KJLoger.debug(date);
							WebData webdata = TcJsParser.getWedataData(date);
							if (webdata.getStatus() == 1) {
								showCustomToast("确认成功");
								refreashZcOrder(info);
							} else {
								showCustomToast(webdata.getMsg());
							}
						} catch (UnsupportedEncodingException e) {
							e.printStackTrace();
						}
						super.onSuccess(t);
					}
				});

	}

	/**
	 * 
	 * @Description: 广播刷新订单状态
	 * @return void
	 * @throws
	 * @autour wzq
	 * @date 2015-9-14 下午4:16:59
	 * @update (date)
	 */
	@SuppressLint("NewApi")
	private void registReceiver() {
		intentFilter = new IntentFilter();
		intentFilter.addAction(TCBroadcastAction.SUCCESS_CANCEL_CARGO);
		intentFilter.addAction(TCBroadcastAction.SUCCESS_WX_PAY_OK);
		intentFilter.addAction(TCBroadcastAction.ERROR_WX_PAY_CANCEL);
		intentFilter.addAction(TCBroadcastAction.DIALOG_SHOW);
		intentFilter.addAction(TCBroadcastAction.SUC_CONFIRM_MODIFY);
		intentFilter.addAction(TCBroadcastAction.ERROR_CONFIRM_MODIFY);
		registerReceiver(receiver, intentFilter);
	}

	private BroadcastReceiver receiver = new BroadcastReceiver() {

		@Override
		public void onReceive(Context context, Intent intent) {
			if (TCBroadcastAction.SUCCESS_CANCEL_CARGO.equals(intent
					.getAction())) {
				refreashZcOrder(info);
			}
			
			if (TCBroadcastAction.SUCCESS_WX_PAY_OK.equals(intent.getAction())) {
				refreashZcOrder(info);
				if (TcLoaddingDialog != null && TcLoaddingDialog.isShowing()) {
					TcLoaddingDialog.cancel();
				}
				ViewInject.toast("订单支付成功");
			}

			if (TCBroadcastAction.ERROR_WX_PAY_CANCEL
					.equals(intent.getAction())) {
				ViewInject.toast("订单支付失败");
			}
			if (TCBroadcastAction.ERROR_CONFIRM_MODIFY.equals(intent
					.getAction())) {
				ViewInject.toast("确定修改失败");
			}
			if (TCBroadcastAction.SUC_CONFIRM_MODIFY.equals(intent.getAction())) {
				ViewInject.toast("确定修改成功");
			}

		}
	};

	/**
	 * 
	 * @Description: 刷写正常的订单
	 * @param zcOrder
	 * @return void
	 * @throws
	 * @autour wzq
	 * @date 2015-9-21 下午5:22:51
	 * @update (date)
	 */
	private void refreashZcOrder(ZcOrderInfo zcOrder) {
		TcLoaddingDialog.show();
		HttpConfig config = new HttpConfig();
		config.cacheTime = 0;
		KJHttp kjHttp = new KJHttp(config);
		HttpParams params = new HttpParams();
		params = HttpParamUtil.getCargoOrderInfoParams(getApplicationContext(),
				zcOrder.getZcOrderId());
		kjHttp.post(TcWebservice.WEBSERVER_IP
				+ TcWebservice.API.FREIGHT_ORDER_DETAIL, params,
				new HttpCallBack() {
					@Override
					public void onFailure(int errorNo, String strMsg) {
						super.onFailure(errorNo, strMsg);
					}

					@Override
					public void onSuccess(String t) {
						try {
							String date = URLDecoder.decode(t, "UTF-8");
							KJLoger.debug(date);
							WebData webdata = TcJsParser.getWedataData(date);
							if (webdata.getStatus() == 1) {
								ZcOrderInfo newOrderInfo = JSON.parseObject(
										webdata.getData(), ZcOrderInfo.class);
								initBaseInfo(newOrderInfo);
							} else {

							}
							if (TcLoaddingDialog.isShowing()) {
								TcLoaddingDialog.cancel();
							}
						} catch (UnsupportedEncodingException e) {
							e.printStackTrace();
						}
						super.onSuccess(t);
					}
				});
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		unregisterReceiver(receiver);
	}
}
